-- transfiguration
-- create by panyl
-- 变形，属性攻击N%

return {
    apply = function(prop, baseValue)
        local v = FormulaM.invoke("CALC_BIG_DIVISION", baseValue, prop[3], 1000);

        return baseValue - v;
    end,

    clear = function(who, prop)
        local force = tonumber(prop[3]);
        -- 血量还原一下
        local currHp = who:getHp();
        local addHp = math.modf(force / (1000 - force) * currHp);
        who:setRealHp(currHp + addHp);

        -- 重新刷一下属性
        PropM.refresh(who);

        -- 刷新下光环属性
        AssistMonsterM.updateAssistData();

        -- 抛出一个事件就行了
        if who.type == OBJECT_TYPE_MONSTER then
            -- 怪物清除了“失明”事件
            EventMgr.fire(event.GRID_LOCK_STATE, {["pos"] = who:getPos(), });

            -- 抛出更新警戒效果事件
            EventMgr.fire(event.UPDATE_ALERT, {["classId"] = who:getClassId()});
        end

        if who.type == OBJECT_TYPE_GHOST_SHIP or who.type == OBJECT_TYPE_MONSTER then
            -- 怪物还原模型
            EventMgr.fire(event.GRID_ORI_MODEL, {["pos"] = who:getPos(),});
        end
    end,

    record = function(target, prop, path)
        if (target.type == OBJECT_TYPE_MONSTER
            or target.type == OBJECT_TYPE_GHOST_SHIP)
            and not target:isDead() then
            -- 怪物或者幽灵船，变形术变青蛙
            local dbase = {};
            if target.type == OBJECT_TYPE_MONSTER then
                dbase = MonsterM.query(target.classId, "dbase") or {};
            end

            if target:isBoss() and dbase["slime_display"] ~= 1 then
                target.dbase:set("changeClassId", 1);
            else
                target.dbase:set("changeClassId", 2);
            end

            -- 抛出更新警戒效果事件
            if target.type == OBJECT_TYPE_MONSTER then
                EventMgr.fire(event.UPDATE_ALERT, {["classId"] = target:getClassId()});
            end
        end
        return false;
    end
};
